import request from '/@/utils/request';

/**
 * 用户登录
 * @param params 要传的参数值
 * @returns 返回接口数据
 * 登录api接口集合
 * @method login 用户登录
 * @method logout 用户退出登录
 */
export function useLoginApi() {
	return {
		// 登录方法
		login: (loginData: any) => {
			return request({
				url: '/system/login',
				method: 'post',
				data: loginData,
			});
		},
		// 获取用户详细信息
		getInfo: () => {
			return request({
				url: '/system/get-permission-info',
				method: 'get'
			});
		},
		// 退出方法
		logout: () => {
			return request({
				url: '/system/logout',
				method: 'post',
			});
		},
		// 获取验证码
		getCodeImg: () => {
			return request({
				url: '/system/captcha/get-image',
				method: 'get',
				timeout: 20000
			});
		},
		// 社交授权的跳转
		socialAuthRedirect: (type: string, redirectUri: string) => {
			return request({
				url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
				method: 'get'
			});
		},
		// 社交登录，使用 code 授权码
		socialLogin: (type: any, code: any, state: any) => {
			return request({
				url: '/system/social-login',
				method: 'post',
				data: {
					type,
					code,
					state
				}
			});
		},
		// 社交登录，使用 code 授权码 + + 账号密码
		socialLogin2: (type: any, code: any, state: any, username: any, password: any) => {
			return request({
				url: '/system/social-login2',
				method: 'post',
				data: {
					type,
					code,
					state,
					username,
					password
				}
			});
		},
		// 社交绑定，使用 code 授权码
		socialBind: (type: any, code: any, state: any) => {
			return request({
				url: '/system/social-bind',
				method: 'post',
				data: {
					type,
					code,
					state,
				}
			});
		},
		// 取消社交绑定
		socialUnbind: (type: any, unionId: any) => {
			return request({
				url: '/system/social-unbind',
				method: 'delete',
				data: {
					type,
					unionId
				}
			});
		},
	};
}
